﻿using System;
using System.Collections.Generic;
using System.Text;

public class Motorcycle : Vehicle
{
    private const int m_DefaultWheelAirPressure = 32;
    private const int m_NumOfWheels = 2;
    private const string k_LicenseType = "Please enter the license type of the motorcycle (1. A1, 2. A2, 3. A3, 4. B:";
    private const string k_EngineCC = "Please enter the engine cc:";
    private eLicenseType? m_LicenseType;
    private int? m_EngineCC = null;

    public Motorcycle()
    {
        this.AllocateVehicleProperties();
    }

    public enum eLicenseType
    {
        A1 = 1,
        A2,
        A3,
        B
    }

    private enum eVehiclePropertyIndex
    {
        EngineType = 0,
        ModelName,
        WheelManufacturer,
        LicenseType,
        EngineCC
    }

    public new virtual string ToString()
    {
        string ResultStr = base.ToString();
        string[] PropertiesStrArray = new string[] { "License type: ", m_LicenseType.ToString(), System.Environment.NewLine, "Engine CC: ", m_EngineCC.ToString(), System.Environment.NewLine };

        ResultStr = string.Concat(ResultStr, PropertiesStrArray);
        return ResultStr;
    }

    protected override void AllocateVehicleProperties()
    {
        base.AllocateVehicleProperties();

        m_NumOfProperties = 5;

        m_VehicleProperties.Add(new VehicleProperty(k_LicenseType, 3, m_LicenseType));
        m_VehicleProperties.Add(new VehicleProperty(k_EngineCC, 4, m_EngineCC));
    }

    public override void SetVehicleProperty(VehicleProperty i_VehiclePropertyToSet)
    {
        eVehiclePropertyIndex VehiclePropertyToSetIndex = (eVehiclePropertyIndex)i_VehiclePropertyToSet.VehiclePropertyIndex.Value;
        object VehiclePropertyValue = i_VehiclePropertyToSet.VehiclePropertyValue;

        switch (VehiclePropertyToSetIndex)
        {
            case eVehiclePropertyIndex.EngineType:
                {
                    this.AllocateNewEngine(VehiclePropertyValue);
                    break;
                }

            case eVehiclePropertyIndex.ModelName:
                {
                    m_ModelName = VehiclePropertyValue.ToString();
                    break;
                }

            case eVehiclePropertyIndex.WheelManufacturer:
                {
                    m_WheelManufacturer = VehiclePropertyValue.ToString();
                    this.InitilizeWheels(m_NumOfWheels, Wheel.ePressureType.Motorcycle, m_WheelManufacturer);
                    break;
                }

            case eVehiclePropertyIndex.LicenseType:
                {
                    m_LicenseType = (eLicenseType)ValidateEnumRanges(typeof(eLicenseType), VehiclePropertyValue);
                    break;
                }

            case eVehiclePropertyIndex.EngineCC:
                {
                    m_EngineCC = int.Parse(VehiclePropertyValue.ToString());
                    break;
                }
        }
    }

    protected override void AllocateNewEngine(object i_VehiclePropertyValue)
    {
        Engine.eEngineType CurrentVehicleEngineType = (Engine.eEngineType)ValidateEnumRanges(typeof(Engine.eEngineType), i_VehiclePropertyValue);

        if (CurrentVehicleEngineType.Equals(Engine.eEngineType.Fuel))
        {
            this.Engine = new FuelEngine(FuelEngine.eEngineFuelType.Octan98, 7);
        }
        else if (CurrentVehicleEngineType.Equals(Engine.eEngineType.Electric))
        {
            this.Engine = new ElectricEngine(1.7f);
        }
    }
}
